import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'BLNET', icon: 'dashboard' }
    }]
  },

  {
    path: '/status',
    component: Layout,
    redirect: '/status',
    children: [{
      path: 'status',
      name: 'Status',
      component: () => import('@/views/status/index'),
      meta: { title: '状态', icon: 'status' }
    }]
  },
  {
    path: '/network',
    component: Layout,
    redirect: '/network/lanIntranet',
    meta: { title: '网络', icon: 'network' },
    children: [
      {
        path: 'info',
        name: 'Info',
        component: () => import('@/views/network/info'),
        meta: { title: '数采信息'}
      },
      {
        path: 'collect',
        name: 'Collect',
        component: () => import('@/views/network/collect'),
        meta: { title: '数采配置'}
      },
      {
        path: 'lanIntranet',
        name: 'LanIntranet',
        component: () => import('@/views/network/lanIntranet'),
        meta: { title: 'LAN内网'}
      },
      {
        path: 'wifi',
        name: 'Wifi',
        component: () => import('@/views/network/wifi'),
        meta: { title: 'WIFI网络'}
      },
      {
        path: 'log',
        name: 'Log',
        component: () => import('@/views/network/log'),
        meta: { title: '网关日志'}
      },
      {
        path: 'cloudServer',
        name: 'CloudServer',
        component: () => import('@/views/network/cloudServer'),
        meta: { title: '云服务中心'}
      },
      {
        path: 'staticRouter',
        name: 'StaticRouter',
        component: () => import('@/views/network/staticRouter'),
        meta: { title: '静态路由'}
      },
      {
        path: 'diagnose',
        name: 'Diagnose',
        component: () => import('@/views/network/diagnose'),
        meta: { title: '网络诊断'}
      },
      {
        path: 'qualityService',
        name: 'QualityService',
        component: () => import('@/views/network/service'),
        meta: { title: '服务质量'}
      }
  ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/index',
    meta: { title: '系统', icon: 'service' },
    children: [
      {
        path: 'system',
        name: 'System',
        component: () => import('@/views/system/timeSync'),
        meta: { title: '时间同步' }
      },
      {
        path: 'mount',
        name: 'Mount',
        component: () => import('@/views/system/mount'),
        meta: { title: '挂载点' }
      },
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/system/index'),
        meta: { title: '系统' }
      }
    ]
  },
  {
    path: '/transpond',
    component: Layout,
    children: [
      {
        path: 'transpond',
        name: 'Transpond',
        component: () => import('@/views/transpond/index'),
        meta: { title: '转发中心', icon: 'transpond' }
      }
    ]
  },
  {
    path: '/service',
    component: Layout,
    redirect: '/service/index',
    meta: { title: '服务', icon: 'service' },
    children: [
      {
        path: 'lcmp',
        name: 'Lcmp',
        component: () => import('@/views/service/lcmp'),
        meta: { title: 'lcmp看门狗'}
      },
      {
        path: 'serviceIndex',
        name: 'ServiceIndex',
        component: () => import('@/views/service/index'),
        meta: { title: '服务'}
      }
    ]
  },
  {
    path: '/vpn',
    component: Layout,
    children: [
      {
        path: 'vpn',
        name: 'Vpn',
        component: () => import('@/views/vpn/index'),
        meta: { title: 'VPN', icon: 'vpn' }
      }
    ]
  },
  {
    path: '/firewall',
    component: Layout,
    children: [
      {
        path: 'firewall',
        name: 'Firewall',
        component: () => import('@/views/firewall/index'),
        meta: { title: '防火墙', icon: 'firewall' }
      }
    ]
  },
  {
    path: '/dict',
    component: Layout,
    children: [
      {
        path: 'dict',
        name: 'Dict',
        component: () => import('@/views/dict/index'),
        meta: { title: '字典管理',icon: 'el-icon-collection'  }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
